package com.hdey.handler.max;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class DateHandler implements MetaObjectHandler {

    //插入时 填充策略
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("开始插入注入");
        this.setFieldValByName("createDate",new Date(),metaObject);
        this.setFieldValByName("updateDate",new Date(),metaObject);
        //this.strictInsertFill(metaObject, "createDate", LocalDate.class, LocalDate.now());
        //this.strictUpdateFill(metaObject, "updateDate", LocalDate.class, LocalDate.now());
    }

    //修改时 填充策略
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("开始修改注入");
        this.setFieldValByName("updateDate",new Date(),metaObject);
        //this.strictUpdateFill(metaObject, "updateDate", LocalDate.class, LocalDate.now());
    }
}
